package com.ruoyi.shop.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.shop.api.RemoteShopImageService;

import com.ruoyi.shop.api.domain.CheShopImage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;

/**
 * 文件服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteRemoteShopImageFallbackFactory implements FallbackFactory<RemoteShopImageService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteRemoteShopImageFallbackFactory.class);


    @Override
    public RemoteShopImageService create(Throwable throwable) {
        log.error("商户服务调用失败:{}", throwable.getMessage());
        return new RemoteShopImageService() {
            @Override
            public TableDataInfo list(CheShopImage cheShopImage, String source) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("获取商家照片列表失败: " + throwable.getMessage());
                tableDataInfo.setRows(new java.util.ArrayList<>());
                tableDataInfo.setTotal(0);
                return tableDataInfo;
            }

            @Override
            public void export(HttpServletResponse response, CheShopImage cheShopImage, String source) {
            }

            @Override
            public AjaxResult getInfo(Long shopImageId, String source) {
                return AjaxResult.error("通过id获取商家照片信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult add(CheShopImage cheShopImage, String source) {
                return AjaxResult.error("新增商家照片失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult edit(CheShopImage cheShopImage, String source) {
                return AjaxResult.error("修改商家照片失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult remove(Long[] shopImageIds, String source) {
                return AjaxResult.error("删除商家照片失败:" + throwable.getMessage());
            }
        };
    }
}

